
// 定义shopcarslice
import { createSlice } from '@reduxjs/toolkit';
//02:第二步: 创建购物车切片
const shopcarSlice = createSlice({
    name: 'shopcar', // 相当于vuex 中命名空间, 给切片命名,
    initialState: { // 定义当前切片的初始数据的
        count: 0,
        shoplist: [
            {
                id: 0,
                name: '小黑瓶'
            },
            {
                id: 1,
                name: '迪奥口红'
            },
            {
                id: 2,
                name: '大宝'
            }
        ]
    },
    reducers: {
        addcount(state, actions) {
            console.log('actions', actions);
            state.count += 1
        },
        jiancount(state, actions) {
            state.count -= actions.payload
        }
    }
})

// 第三步: 
export const { addcount, jiancount } = shopcarSlice.actions;

export default shopcarSlice